//
//  LXTimeChooseView.m
//  ZuLinProject
//
//  Created by bancheng on 2022/9/5.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXTimeChooseView.h"

@implementation LXTimeChooseView

- (void)awakeFromNib{
    [super awakeFromNib];
    
    [self.leftTimeBtn setTitle:[NSString getNowDateWithFormat:@"yyyy-MM-dd"] forState:UIControlStateNormal];
    [self.rightTimeBtn setTitle:[NSString getNowDateWithFormat:@"yyyy-MM-dd"] forState:UIControlStateNormal];
    
}

- (IBAction)clickLeftBtn:(UIButton *)sender {
    
    
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.leftTimeBtn.titleLabel.text withIsMaxDate:YES withNoForward:YES WithTips:@"请选择时间"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    datePicker.block = ^(NSString *yearString){
        if([NSString compareDate:yearString withDate:self.rightTimeBtn.titleLabel.text withFormat:@"yyyy-MM-dd"]== -1){
            showAlert(@"开始时间不能大于结束时间");
        }
        else {
            [self.leftTimeBtn setTitle:yearString forState:UIControlStateNormal];
            if (self.clickCellBlock) {
                self.clickCellBlock(yearString,1);
            }
        }
        
    };
    
}

- (IBAction)clickRightBtn:(UIButton *)sender {
    
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.rightTimeBtn.titleLabel.text withIsMaxDate:YES withNoForward:YES WithTips:@"请选择时间"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    datePicker.block = ^(NSString *yearString){
        if([NSString compareDate:self.leftTimeBtn.titleLabel.text withDate:yearString withFormat:@"yyyy-MM-dd"]==-1){
            showAlert(@"结束时间不能小于开始时间");
        }
        else {
            [self.rightTimeBtn setTitle:yearString forState:UIControlStateNormal];
            if (self.clickCellBlock) {
                self.clickCellBlock(yearString,2);
            }
        }
    };
    
    
}


@end
